package com.ruoyi.performance.controller;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.performance.domain.PerfGroup2DTarget;
import com.ruoyi.performance.service.PerfGroup2DTargetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("perfgroupdtarget")
public class PerfGroup2DTargetController extends BaseController {
    @Autowired
    PerfGroup2DTargetService perfGroup2DTargetService;

    @RequestMapping("get/{id}")
    public R list(@PathVariable Long id){
        return jacResult(perfGroup2DTargetService.selectPerfGroup2DTargetById(id));
    }

    @RequestMapping("getc/{Companycode}")
    public R list(@PathVariable String Companycode){
        return jacResult(perfGroup2DTargetService.selectPerfGroup2DTargetByCompanycode(Companycode));
    }

    @RequestMapping("get/list")
    public R list(PerfGroup2DTarget perfGroup2DTarget){
        startPage();
        return result(perfGroup2DTargetService.selectPerfGroup2DTargetList(perfGroup2DTarget));
    }

//    @RequestMapping("get/{detailtargetcode}")
//    public R list(@PathVariable String detailtargetcode){
//        return jacResult(perfGroup2DTargetService.selectByDetailtargetcode(detailtargetcode));
//    }

    @PostMapping("save")
    public R PlaceOrder( @RequestBody List<PerfGroup2DTarget> perfGroup2DTargets){
        List<String> answers = new ArrayList<>();
        System.out.println(JSON.toJSONString(perfGroup2DTargets));
        for (PerfGroup2DTarget perfGroup2DTarget : perfGroup2DTargets) {
            System.out.println(JSON.toJSONString(perfGroup2DTarget));
            perfGroup2DTargetService.insertPerfGroup2DTarget(perfGroup2DTarget);
        }
        return R.ok();

//        JSONArray jsonArray = jsonObject.getJSONArray("initTree");
//        System.out.println(perfGroup2User);
    }

//    @PostMapping("save")
//    public R addSave(@RequestBody PerfGroup2DTarget perfGroup2DTarget){
//        return toAjax(perfGroup2DTargetService.insertPerfGroup2DTarget(perfGroup2DTarget));
//    }

    @PostMapping("update")
    public R editSave(@RequestBody PerfGroup2DTarget perfGroup2DTarget){
        return toAjax(perfGroup2DTargetService.updatePerfGroup2Dtarget(perfGroup2DTarget));
    }

    @PostMapping("remove")
    public R remove( String id){
        return toAjax(perfGroup2DTargetService.deletePerfGroup2DtargetById(id));
    }
}
